<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <!--    <link rel="stylesheet" href="https://yeqian-blog.oss-cn-beijing.aliyuncs.com/js/editormd.css"/>
        <link rel="stylesheet" href="https://yeqian-blog.oss-cn-beijing.aliyuncs.com/js/index2.css">
        <link rel="stylesheet" href="https://yeqian-blog.oss-cn-beijing.aliyuncs.com/js/index.css">
        <script th:src="https://yeqian-blog.oss-cn-beijing.aliyuncs.com/js/utlis.js"></script>-->

    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>注册-你离开了南京，从此没有人和我说话</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" th:href="@{/js/index2.css}">
    <link rel="stylesheet" href="https://yeqian-blog.oss-cn-beijing.aliyuncs.com/js/index.css">
    <link rel="stylesheet" th:href="@{/admin/assets/vendor/bootstrap/css/bootstrap.min.css}">
    <link rel="shortcut icon" href="https://yeqian-blog.oss-cn-beijing.aliyuncs.com/js/bitbug_favicon.ico"/>
    <link rel="stylesheet" th:href="@{/admin/assets/libs/css/style.css}">
    <script th:src="@{/js/utlis.js}"></script>
    <style>
        html,
        body {
            height: 100%;
        }

        body {
            display: -ms-flexbox;
            display: flex;
            -ms-flex-align: center;
            align-items: center;
            padding-top: 40px;
            padding-bottom: 40px;
        }
    </style>
</head>

<body style="background:#f4f4f5;">

<div id="app" class="splash-container" v-cloak>
    <div class="card " style=" border-radius: 10px;">
        <div class="card-header text-center"><a class="navbar-brand" style="color:#007bff;">BLOG-YEQIAN</a>
            <span class="splash-description" style="color: #0a001f">创建你的账号.</span></div>
        <div class="card-body">
            <!-- action="/regist" method="post"-->
            <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" class="demo-ruleForm">
                <el-form-item prop="username">
                    <el-input placeholder="用户名" v-model="ruleForm.username" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input type="password" placeholder="密 码" v-model="ruleForm.password"
                              autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item prop="checkPass">
                    <el-input type="password" placeholder="确 认 密 码" v-model="ruleForm.checkPass"
                              autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button class="btn btn-primary btn-lg btn-block" @click="submitForm('ruleForm')">注册</el-button>
                </el-form-item>
            </el-form>
            <!--  <form  :model="ruleForm" status-icon :rules="rules" ref="ruleForm">
                  <div class="form-group">
                      <input class="form-control form-control-lg" style=" border-radius: 4px;" type="text" name="username"
                             placeholder="用户名" autocomplete="off">
                  </div>
                  <div class="form-group">
                      <el-form-item label="密码" prop="pass">
                          <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
                      </el-form-item>
                  &lt;!&ndash;    <input class="form-control form-control-lg" style=" border-radius: 4px;" type="password" id="pwd"
                             placeholder="密 码" name="password"  v-model="ruleForm.pass" autocomplete="off"
                      >&ndash;&gt;
                  </div>
                  <div class="form-group">
                      <input class="form-control form-control-lg" style=" border-radius: 4px;" type="password" id="repwd"
                             placeholder="确 认 密 码" name="password"
                      >
                  </div>
                  <div id="repwd_prompt"></div>
                  <button type="submit" style=" border-radius: 4px;" class="btn btn-primary btn-lg btn-block" >注 册</button>
              </form>-->
        </div>
    </div>
    <div style="text-align: center; margin-top: 100px; color: #0a001f; padding-bottom: 20px;
"><span>COPYRIGHT © 2020-2021 版权所有 泉眼无声惜细流</span><br/>
        <a href="https://www.miit.gov.cn/">备案号:陕ICP备2020013692号</a></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://yeqian-blog.oss-cn-beijing.aliyuncs.com/js/axios-0.18.0.js"></script>
<script src="https://yeqian-blog.oss-cn-beijing.aliyuncs.com/js/index.js"></script>
<script type="text/javascript" src="https://yeqian-blog.oss-cn-beijing.aliyuncs.com/js/jquery.min.js"></script>
<script type="text/javascript">

    new Vue({
        el: "#app",
        data: function () {
            var checkAge = (rule, value, callback) => {
                if (!value) {
                    return callback(new Error('年龄不能为空'));
                }
                setTimeout(() => {
                    if (!Number.isInteger(value)) {
                        callback(new Error('请输入数字值'));
                    } else {
                        if (value < 18) {
                            callback(new Error('必须年满18岁'));
                        } else {
                            callback();
                        }
                    }
                }, 1000);
            };
            var validatePass = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请输入密码'));
                } else {
                    if (this.ruleForm.checkPass !== '') {
                        this.$refs.ruleForm.validateField('checkPass');
                    }
                    callback();
                }
            };
            var validatePass2 = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请再次输入密码'));
                } else if (value !== this.ruleForm.password) {
                    callback(new Error('两次输入密码不一致!'));
                } else {
                    callback();
                }
            };
            return {
                ruleForm: {
                    password: '',
                    checkPass: '',
                },
                rules: {
                    password: [
                        {validator: validatePass, trigger: 'blur'}
                    ],
                    checkPass: [
                        {validator: validatePass2, trigger: 'blur'}
                    ],
                    age: [
                        {validator: checkAge, trigger: 'blur'}
                    ]
                }
            };
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        console.log(this.ruleForm);
                         axios.post("/admin/regist",this.ruleForm).then((res)=>{
                                if (res.data.flag){
                                    this.$message.success("注册成功，即将跳转登录")
                                    Load('/login');//1秒后跳转
                                }
                         });

                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
        }
    });


</script>
</body>
</html>